package com.shop.milk_tea_shop.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 俞静雯
 * @Description 订单通用工具
 * @date 2024-06-26  15:46
 */
public class OrderUtils {

    public static String getOrderId(String maxOrderId, Character pickup, Long shopId) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String formatDate = simpleDateFormat.format(new Date());
        //判断数据中的最大单号是否存在，是否包含当前日期
        if (maxOrderId != null && maxOrderId.contains(formatDate)){
            String endNum = maxOrderId.substring(maxOrderId.length() - 4);
            int endIntNum = Integer.parseInt(endNum);
            int newEndIntNum = 10000 + endIntNum + 1;
            String newEndNum = String.valueOf(newEndIntNum).substring(1);
            return pickup + shopId.toString() + formatDate + newEndNum;
        }else{
            return pickup + shopId.toString() + formatDate + "0001";
        }
    }

    public static String getPickupNumber(String orderId) {
        return orderId.substring(0,1) + orderId.substring(orderId.length() - 4);
    }
}
